import Vue from "vue"
import Vuex from 'vuex'
Vue.use(Vuex)

const actions = {}

const mutations = {
    //改变登录状态
    changeLoginStatus(state,value){
        // console.log("state",state);
        // console.log("value",value);
        state.loginStatus = value;
    },
    getUserName(state,value){
        state.userName = value;
    },
    changeUserRole(state,value){
        state.userRole = value;
    },
    changeProducts(state,value){
        state.products = value;
    },
    changeCategoryId(state,value){
        state.categoryId = value;
    },
    changePageInfo(state,value){
        state.pageInfo = value;
    },
    changeSearchName(state,value){
        state.searchName = value;
    },
    changeCollects(state,value){
        state.collects = value;
    },
    changeCartList(state,value){
        state.cartList = value;
    },
    chnageGoods(state,value){
        state.goods = value;
    }
    // changeCategoryList(state,value){
    //     state.categoryList = value;
    // }
}
const state = {
    loginStatus:window.sessionStorage.getItem('token')!=null || false,
    userName:window.sessionStorage.getItem('userName') || '',
    userRole:window.sessionStorage.getItem('userRole') || '',
    products:[],
    categoryId:'',
    pageInfo:{},
    searchName:'',
    goods:JSON.parse(window.sessionStorage.getItem('goods'))||[],
    collects:JSON.parse(window.sessionStorage.getItem('collects')) || [],
    cartList:JSON.parse(window.sessionStorage.getItem('cartList')) || [],
    
    // categoryList:[]

}

//创建并暴露store
export default new Vuex.Store({
    actions,
    mutations,
    state
})